/**
 * Created by Xiaoming on 2017/8/29.
 */
angular.module('service.auth', [
        "ngResource",
    ])
    .service('AuthUserService', AuthUserService);
AuthUserService.$inject = ['$cookies'];
function AuthUserService ($cookies) {
    // 读取登录缓存
    this.getUserByCookies = function () {
        var user = {};
        if ($cookies.get('_userId')) {
            user = {
                userId: $cookies.get('_userId'),
                name: $cookies.get('_userName'),
                logo: $cookies.get('_userLogo')
            };
        }
        return user;
    };
    // 读取登录缓存userId
    this.getUserByIdCookies = function () {
        var userId = $cookies.get('_userId');
        return userId;
    };
    // 写入登录缓存
    this.addUserToCookies = function (data) {
        $cookies.put('_userId', data.userid)
        //setCookie('_userName', data.nickname, 60);
        $cookies.put('_userName', data.nickname);
        if (data.logo) {
            $cookies.put('_userLogo', data.logo);
        } else {
            //delCookie('_userLogo');
            $cookies.remove('_userLogo')
        }
    };
    // 注销登陆
    this.userLogout = function () {
        $cookies.remove('_userId');
        $cookies.remove('_userName');
        $cookies.remove('_userLogo');
    };
}